<?

class moredetail extends yellowpages{

 function sql(){

  $a = func_get_args(); $no='';

  $w=""; $chr=""; $tw='';

  $a[4]=$a[4]-1;



  if(isset($_REQUEST['chr'])){ $w=" and company_$a[2] like '".$_REQUEST['chr']."%'";}

  if(isset($_REQUEST['tw'])) $tw = " and town.town_id=".$_REQUEST['tw'];

  $o="order by ad DESC, company_$a[2]";

  $s = " SELECT company.company_id, company_$a[1], company_add_$a[1], town_name_$a[1], tel_fax, 

			prefix, email_address, internet_address, map, book, ad, 

			ad1_image, profile_$a[1], description_$a[1], products_$a[1], branches_$a[1], hours_$a[1] ";			

  switch($a[0]){

   case "search":

    if($a[2]=='vn')  $no = yellowpages::checkVn($a[3]);

	$more = "and (company_$a[2]$no like '%$a[3]%') $tw";

	if(isset($_REQUEST['kw'])) $more = "and (company_name.idall=".$_REQUEST['kw'].")";

    $sql="$s FROM company, company_name, no_tel, town, company_notes 

		 WHERE (company.company_id=company_name.idall) 

		 and (company.company_id=no_tel.idall) 

		 and (company.company_id = company_notes.company_id) 

		 and (company.town_id=town.town_id) $more"; 

	$sql.="$w $o limit $a[4],1";

	break;

   case "tel":

    $sql="$s

	     FROM company, company_name, no_tel, town, company_notes 

		 WHERE (company.company_id=company_name.idall) 

		 and (company.company_id=no_tel.idall) 

		 and (company.company_id = company_notes.company_id)

		 and (company.town_id=town.town_id)

		 and (tel_fax like '$a[3]%') $tw"; 

	$sql.="$w $o limit $a[4],1";

	break;

   case "comform"://    print_r($a);

   // if(isset($_REQUEST['tw'])) $tw = "and town.town_id=".$_REQUEST['tw'];

    $sql="$s

		 FROM company, company_name, no_tel, town, company_notes 

		 WHERE (company.company_id=company_name.idall) and (company.company_id=no_tel.idall) 

		 and (company.town_id=town.town_id) and (company.company_id = company_notes.company_id)	

		 and (com_form_id=$a[3]) $tw "; 

	$sql.="$w $o limit $a[4],1";

	break;

   case 'trade':

  //  if(isset($_REQUEST['tw'])) $tw = "and town.town_id=".$_REQUEST['tw'];

    $sql="$s 

		FROM company, company_name, no_tel, town, id_trade, company_notes

		WHERE (company.company_id=company_name.idall) and (company.company_id=no_tel.idall) 

		and (company.town_id=town.town_id) and (company.company_id = company_notes.company_id)

		and (company.company_id=id_trade.company_id) and (trade_name_1=$a[3]) $tw ";

	$sql.="$w $o limit $a[4],1";

    break;

   case "productList":

   // if(isset($_REQUEST['tw'])) $tw = "and town.town_id=".$_REQUEST['tw'];

    $sql="$s 

		FROM company, company_name, no_tel, town, id_class, company_notes 

		WHERE (company.company_id=company_name.idall) 

		and (company.company_id=no_tel.idall) 

		and (company.town_id=town.town_id) 

		and (company.company_id = company_notes.company_id)

		and (company.company_id=id_class.company_id) 

		and (class_id_1=$a[3]) $tw ";

	$sql.="$w $o limit $a[4],1";	 

	break;

   case "head":

    $sql = "select head_$a[2], infone_$a[2], inftwo_$a[2],link_$a[2] from vb_memberprofile, vb_custad_en 

			where vb_memberprofile.memID = vb_custad_en.memID and id=$a[1]";

    break;

  }

//  echo("$sql<br>");

  return $sql;

 }

 function showResult(){//$istype, $lang, $_SESSION['lng'], $key, $pg, $ids, $tw,'vn'
  $a = func_get_args(); $fax='';

  $sql = $this->sql($a[0],$a[1],$a[2],$a[3],$a[4]);

  $lnglnk = $a[1];

  if($a[1]=='us') $lnglnk = '';

  $pgno = $this->getPage($sql,$a[4],$a[5],$a[6],"moredetail$lnglnk".$a[7],$a[1]);// $bg,$end,$a[8],$lnglnk,$a[7],$a[4],$chrlnk

  $result = mysql_query($sql);

  $t="<table class=tab cellpadding=0 cellspacing=0 width=100%>";

  $tr = '<tr><td colspan=2>&nbsp;</td></tr>';

  $k = $this->changeLang($a[1]);

  while($rs = mysql_fetch_array($result,MYSQL_NUM)){
   if($rs[11]!='') $rs[11]="<img src=$rs[11] style=margin-right:10px>";
   if(strpos($rs[4],"|")>0){
    $tmp = explode("|",$rs[4]);
	$rs[4] = $tmp[0]; $fax =  $tmp[1];
   }

   if($rs[6]) 

    $eq="feedback$lnglnk.php?ids=$a[5]&url=$rs[6]&kw=".base64_encode($rs[1])."";

   else

    $eq="feedback$lnglnk.php?ids=$a[5]&url=&kw=".base64_encode($rs[1])."";

   $top ="<tr><td align=center style='padding-left:12px' width=10> $rs[11]</td>

   		<td align=right   valign=bottom>[<a title='$k[11]' style=color:black target=_blank href='$eq' class=aa>  $k[11]</a> ]  <a title='$k[12]' class='hand'  onclick=\"printit('print','$a[1]','$a[0]','$a[5]')\" >[ $k[12] ]</a></td></tr>	

		<td height='5'></td></tr>	

		<tr><td colspan=2>

		<table class=tab cellspacing=0 width=100%>

	<tr class=bgCom><td class=pdlr10 height=28><b style=font-size:15px>&nbsp;$rs[1]</b></td>

		<td align=right class=pdlr10></td></tr>

		</table></td></tr>";

  $pr = "<tr><td style=padding:10px colspan=2><b style=font-size:16px>$rs[1]</b></td></tr>

        <tr><td style=padding:10px colspan=2>$rs[11]</td></tr>";

   if($a[1]=='cn')

    $add = "$rs[3], ".str_replace("|","",$rs[2])."<br>";

   else

    $add = str_replace("|","",$rs[2])." $rs[3] <br>";		

	

  $add = "<tr class=bgMore><td class=pdlr10 colspan=2><table class=tab width=100%>

		<tr><td width=1% valign=top nowrap>$k[7]</td><td>".$add."</td></tr>

		<tr><td nowrap>$k[8]</td><td>($rs[5]) $rs[4]</td></tr>";

  if($fax) $add .="<tr><td>$k[9]</td><td>($rs[5]) $fax</td></tr>";

  if(trim($rs[6])) $add .="<tr><td>$k[13]</td>

		<td><a class='lCom aa' target=_blank href='$eq'>$rs[6]</a></td></tr>";

  if(trim($rs[7])){ 

   if(strpos($rs[7],"; ")>0){

    $tmp = explode("; ",$rs[7]); $rs[7]='';

	for($i=0;$i<count($tmp);$i++)

	 $rs[7] .= "<a class='lCom aa' href='http://$tmp[$i]'>$tmp[$i]</a>; ";

	$rs[7] = substr($rs[7],0,strlen($rs[7])-2);

	echo($rs[7]);

   }else

    $rs[7] = "<a class='lCom aa' href='http://$rs[7]' target='_blank'>$rs[7]</a>";

    $add .="<tr><td>$k[14]</td><td>$rs[7]</td></tr>";

  }

  $add .="</table></td></tr>";

   if(trim($rs[12])) $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[0]<br><span style='font-size:4px'>&nbsp;</span><br>".str_replace(chr(13),'<br>',$rs[12])."</td></tr>";

   if(trim($rs[13])) $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[1]<br><font style='font-size:4px'>&nbsp;</font><br>".str_replace(chr(13),'<br>',$rs[13])."</td></tr>";

   if(trim($rs[14])){

   $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[2]<br><font style='font-size:4px'>&nbsp;</font><br>".str_replace(chr(13),'<br>',$rs[14])."</td></tr>";

   }

   $brd = $this->getclstrade($rs[0], 'brand',$a[1]);

   if($brd) $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[3]<br><font style='font-size:4px'>&nbsp;</font><br>$brd</td></tr>";

   if(trim($rs[16])) $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[4]<br><font style='font-size:4px'&nbsp;</font><br>".str_replace(chr(13),'<br>',$rs[16])."</td></tr>";

   if(trim($rs[15])) $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[5]<br><font style='font-size:4px'>&nbsp;</font><br>".str_replace(chr(13),'<br>',$rs[15])."</td></tr>";

   $cls = $this->getclstrade($rs[0], 'class',$a[1]);

   if($cls) $add .= "$tr<tr><td class=bgMore1 style=padding:10px colspan=2>$k[6]<br><font style='font-size:4px'>&nbsp;</font><br>$cls</td></tr>";

  }
  mysql_free_result($result);
  $num = mysql_num_rows(mysql_query($_SESSION['sqlnum']));
  return "$t$top$add<tr><td style=padding-top:20px colspan=2 align=center>$pgno</td></tr>
		  <tr><td colspan=2 align=center>".sprintf($k[17], $num)."</td></tr>
		 <tr><td></td></tr>
		  </table><div id=print style=display:none>$t$pr$add</table></div>";

 }

 

 function getclstrade($id,$type,$lang){

  if($type=='class')

   $sql = "SELECT class_name_$lang FROM class,id_class 

           WHERE (class.class_id = id_class.class_id_1) and(company_id=".$id.") order by sort_no";

  else

   $sql ="SELECT trade_name FROM trade_name,id_trade 

		  WHERE (trade_name.trade_id = id_trade.trade_name_1) and(company_id=".$id.") order by sort_no";

   $result = mysql_query($sql);

   $t='';

   while($rs = mysql_fetch_array($result,MYSQL_NUM))

    $t .="$rs[0] * ";

   return substr($t,0,strlen($t)-2);

 }

 function changeLang($lang){

  $a = array(); //echo($lang);

  switch($lang){

   case 'us':

    $a[0]='<b class=colMore>Company Executive:</b>'; $a[1]='<b class=colMore>Company Description:</b>';

	$a[2]='<b class=colMore>Products & Services:</b>'; $a[3]='<b class=colMore>Brands:</b>';	

	$a[4]='<b class=colMore>Operating Hours:</b>'; $a[5]='<b class=colMore>Other Contact Information:</b>';	

	$a[6]='<b class=colMore>Appears in the Categories:</b>';$a[7]='<b>Address:</b>';$a[8]='<b>Telephone:</b>';

	$a[9]='<b>Fax:</b>'; $a[10] = 'Contact Information'; $a[11]='Enquiry'; $a[12]='Print';$a[13]='<b>Email:</b>';$a[14]='<b>URL:</b>'; $a[15]='<b>Prev</b>'; $a[16]='<b>Next</b>';
	$a[17]="Total: %s records";
	break;

   case 'cn':	

	$a[]='<b class=colMore>公司执行:</b>'; $a[]='<b class=colMore>公司简介:</b>';

	$a[]='<b class=colMore>产品及服务:</b>'; $a[]='<b class=colMore>品牌:</b>'; 

	$a[]='<b class=colMore>营业时间:</b>'; $a[]='<b class=colMore>联络信息:</b>'; 

	$a[]='<b class=colMore>黄页分类:</b>';$a[]='地址:';$a[]='电话:</b>'; $a[]='传真:</b>';

	$a[] = '联络信息'; $a[]='询问'; $a[]='打印';$a[]='邮件:';$a[]='网址:';$a[]='<b>上一页</b>'; $a[]='<b>下一页</b>';
	$a[] = "Tổng cộng: %s hồ sơ";
	break;

   default:

    $a[]='<b class=colMore>Người Điều Hành:</b>'; $a[]='<b class=colMore>Diễn Giải:</b>';

	$a[]='<b class=colMore>Sản Phẩm & Dịch Vụ:</b>'; $a[]='<b class=colMore>Thông Tin Liên Lạc khác:</b>';

	$a[]='<b class=colMore>Thương Hiệu:</b>'; $a[]='<b class=colMore>Giờ làm việc:</b>';

	$a[]='<b class=colMore>Xuất hiện dưới các ngành nghề:</b>';$a[]='<b>Địa Chỉ:</b>';$a[]='<b>Điện Thoại:</b>';

	$a[]='<b>Fax:</b>'; $a[] = 'Thông Tin Liên Hệ'; $a[]='Yêu Cầu'; $a[]='In'; $a[]='<b>Email:</b>';$a[]='<b>URL:</b>';$a[15]='<b>Trước</b>'; $a[16]='<b>Tiếp</b>';
    $a[]="Tổng cộng: %s hồ sơ";
  }

  return $a;

 }

//$sql, $a[4], $a[5], $a[6], $a[7]

  function getPage(){// $bg,$end,$a[8],$lnglnk,$a[7],$a[4],$chrlnk 

  $a = func_get_args();// print_r($a);

  $total = $_SESSION['total']; $lg=$this->changeLang($a[5]);// change lang

  $tw=''; $chr = '';

  if(isset($_REQUEST['tw'])) $tw = "&tw=".$_REQUEST['tw'];

  if(isset($_REQUEST['chr'])) $chr = "&chr=".$_REQUEST['chr'];

   $next="<a href=$a[4].php?pg=".($a[1]+1)."&ids=$a[2] class='style3'><font style=padding-left:3px>$lg[16]</font></a> "; 

  $prev="<a href=$a[4].php?pg=".($a[1]-1)."&ids=$a[2] class='style3'><font style=padding-right:3px>$lg[15]</font></a> ";

  $bg=0; $end=11;

  if($a[1]==$total) $next=""; 

  if($total<$end) $end = $total+1;

  if($a[1]<6){

   if($a[1]==1) $prev="";

  }else{ 

   $bg=$a[1]-5; $end = $bg +11;

   $tmp = $end-$bg;

   if($tmp>=11) $bg=$bg-1;

   if($total<$end) $end--; 

   if($end > $total){

    $end = $total+1;

    $bg = $bg - (5-($total-$a[1]));

	if($bg<0) $bg = 0;

   }

  }

  $t='';



  for($i=$bg;$i<($end-1);$i++){

   $tmp=$i+1;

   if($tmp==$a[1])

      $t.="<font style=padding-right:9px class=page4>[".number_format($tmp)."]</font>";

   else

    $t.="<a class='style3' href=$a[4].php?pg=$tmp&ids=$a[2]><font style=padding-right:10px>".number_format($tmp)."</font></a>";

  }

   if($total==1) $t='';

  return $prev.$t.$next;

}



}

?>